package com.codrim.cs.data.server.utils;

import com.codrim.cs.data.rpc.enums.TimeDimension;

import org.apache.commons.lang3.time.DateFormatUtils;

import java.util.Date;

import lombok.experimental.UtilityClass;

/**
 * @author Liang.Zhuge
 * @date 15/03/2018
 */
@UtilityClass
public class TimeDimensionUtils {
    public static int dateToInt(Date date, TimeDimension timeDimension) {
        String pattern;
        switch (timeDimension) {
            case Hour:
                pattern = "yyyyMMddHH";
                break;
            default:
                pattern = "yyyyMMdd";
                break;
        }
        return Integer.valueOf(DateFormatUtils.format(date, pattern));
    }
}
